﻿using System.Configuration;
using System.Reflection;
using EverBuy.SocialNetworking.Data.EntityFrameworkRepository.DataModel;
using log4net;


namespace EverBuy.SocialNetworking.Data.EntityFrameworkRepository.Abstracts
{
    /// <summary>
    /// 
    /// </summary>
    public abstract class RepositoryBase
    {
        /// <summary>
        /// 
        /// </summary>
        protected static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// 
        /// </summary>
        private static readonly string ConnectionString;

        /// <summary>
        /// Static constructor. Reads the connectionstring from web.config just once.
        /// </summary>
        static RepositoryBase()
        {
            var connectionStringName = ConfigurationManager.AppSettings.Get("ConnectionStringName");
            ConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
        }

        /// <summary>
        /// Creates the Context using the current connectionstring.
        /// </summary>
        /// <remarks>
        /// Gof pattern: Factory method. 
        /// </remarks>
        /// <returns>SocialNetwork Entities context.</returns>
        public static SevenTalkEntities DataContext
        {
            get
            {
                return new SevenTalkEntities(ConnectionString);
            }
        }
    }
}
